home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Car / Inspector.m < prev    next >
Encoding:
Text File  |  1992-06-23  |  14.6 KB  |  519 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <rpcsvc/bootparam.h>
  5. #import <appkit/Button.h>
  6. #import <appkit/Matrix.h>
  7. #import <appkit/Form.h>
  8. #import <appkit/Panel.h>
  9. #import <appkit/Box.h>
  10. #import <strings.h>
  11. #import "Car_main.h"
  12. #import "Inspector.h"
  13. #import "Road.h"
  14. #import "Car.h"
  15. #import "Controller.h"
  16. #import "Transmission.h"
  17. #import "Engine.h"
  18. #import "GasTank.h"
  19. #import "Motor.h"
  20. #import "Battery.h"
  21. #import "Wheels.h"
  22. #import "Cycle.h"
  23. #import "AppDelegate.h"
  24. #import "DataView.h"
  25.  
  26. static char windowTitles[10][MAX_PATH_LEN] = {"Environment Inspector",
  27.                                                "Car Inspector",
  28.                                                "Controller Inspector",
  29.                                                "Transmission Inspector",
  30.                                                "Engine Inspector",
  31.                                                "Gas Tank Inspector",
  32.                                                "Motor Inspector",
  33.                                                "Battery Inspector",
  34.                                                "Wheel Inspector",
  35.                                                "Cycle Inspector"};
  36. @implementation Inspector
  37.  
  38. // These are just some workarounds to a simple problem.  The variables from the nib file have not been initialized yet.
  39.  
  40. - init
  41. {
  42.    inspector = self;
  43.    return self;
  44. }
  45.  
  46. - setRoadBox:anObject;
  47. {
  48.     roadBox = anObject;
  49.     boxList[0] = anObject;
  50.     return self;
  51. }
  52.  
  53. - OKRoadBox:sender
  54. {
  55.     [road setTemperature:[roadTemperature floatValue]];
  56.     [road setWindSpeed:[roadWindSpeed floatValue]];
  57.     return self;
  58. }
  59.  
  60. - revertRoadBox:sender
  61. {   
  62.     [roadTemperature setFloatValue:[road temperature]];
  63.     [roadWindSpeed setFloatValue:[road windSpeed]];
  64.     return self;
  65. }
  66.  
  67. - loadRoad:sender
  68. {
  69. char *filename;
  70.  
  71.     filename = [appDelegate openFileType:"environment"];
  72.     [self updateRoadGraph:filename];
  73.     return self;
  74. }
  75.  
  76. - updateRoadGraph:(const char *)filename
  77. {
  78.     strcpy(windowTitles[0],filename);
  79.     [roadGraph setData:[road data]];
  80.     [inspectorPanel setTitleAsFilename:windowTitles[0]];
  81.     [self OKCycleBox:self];
  82.     [roadLength setFloatValue:[roadGraph xmax]];
  83.     [inspectorPanel display];
  84.     return self;
  85. }
  86.  
  87. - setCarBox:anObject;
  88. {
  89.     carBox = anObject;
  90.     boxList[1] = anObject;
  91.     return self;
  92. }
  93.  
  94. - OKCarBox:sender
  95. {
  96.     [car setDragCoefficient:[carDragCoefficient floatValue]];
  97.     [car setFrontalArea:[carFrontalArea floatValue]];
  98.     [car setMass:[carMass floatValue]];
  99.     [car setPlotAcceleration:[carPlotAcceleration state]];
  100.     [car setTestMode:[carTestMode selectedRow]];
  101.     return self;
  102. }
  103.  
  104. - revertCarBox:sender
  105. {
  106.     [carDragCoefficient setFloatValue:[car dragCoefficient]];
  107.     [carFrontalArea setFloatValue:[car frontalArea]];
  108.     [carMass setFloatValue:[car mass]];
  109.     [carPlotAcceleration setState:[car plotAcceleration]];
  110.     [carTestMode selectCellAt:[car testMode] :0];
  111.     return self;
  112. }
  113.  
  114. - updateCarBox:(const char *)filename
  115. {
  116.     strcpy(windowTitles[1],filename);
  117.     [inspectorPanel setTitleAsFilename:windowTitles[1]];
  118.     [inspectorPanel display];
  119.     return self;
  120. }
  121.  
  122. - setControllerBox:anObject;
  123. {
  124.     controllerBox = anObject;
  125.     boxList[2] = anObject;
  126.     return self;
  127. }
  128.  
  129. - OKControllerBox:sender
  130. {
  131.     [controller setMass:[controllerMass floatValue]];
  132.     [controller setShiftCeiling:[controllerShiftCeiling floatValue]];
  133.     [controller setShiftFloor:[controllerShiftFloor floatValue]];
  134.     return self;
  135. }
  136.  
  137. - revertControllerBox:sender
  138. {
  139.     [controllerMass setFloatValue:[controller mass]];
  140.     [controllerShiftCeiling setFloatValue:[controller shiftCeiling]];
  141.     [controllerShiftFloor setFloatValue:[controller shiftFloor]];
  142.     return self;
  143. }
  144.  
  145. - setTransmissionBox:anObject;
  146. {
  147.     transmissionBox = anObject;
  148.     boxList[3] = anObject;
  149.     return self;
  150. }
  151.  
  152. - OKTransmissionBox:sender
  153. {
  154. float gearRatios[5];
  155. float shiftPoints[4];
  156. int i;
  157.  
  158.     [transmission setCurrentGear:[transmissionCurrentGear intValue]];
  159.     [transmission setEfficiency:[transmissionEfficiency floatValue]];
  160.     [transmission setFinalDriveRatio:[transmissionFinalDriveRatio floatValue]];
  161.     for ( i = 0 ; i < 5 ; i++ )
  162.         gearRatios[i] = [transmissionGearRatios floatValueAt:i];
  163.     [transmission setGearRatios:gearRatios];
  164.     [transmission setMass:[transmissionMass floatValue]];
  165.     [transmission setShiftLag:[transmissionShiftLag floatValue]];
  166.     for ( i = 0 ; i < 4 ; i++ )
  167.         shiftPoints[i] = [transmissionShiftPoints floatValueAt:i];
  168.     [transmission setShiftPoints:shiftPoints];
  169.     return self;
  170. }
  171.  
  172. - revertTransmissionBox:sender
  173. {
  174. float *gearRatios;
  175. float *shiftPoints;
  176. int i;
  177.  
  178.     [transmissionCurrentGear setIntValue:[transmission currentGear]];
  179.     [transmissionEfficiency setFloatValue:[transmission efficiency]];
  180.     [transmissionFinalDriveRatio setFloatValue:[transmission finalDriveRatio]];
  181.     gearRatios = [transmission gearRatios];
  182.     for ( i = 0 ; i < 5 ; i++ )
  183.         [transmissionGearRatios setFloatValue:gearRatios[i] at:i];
  184.     [transmissionMass setFloatValue:[transmission mass]];
  185.     [transmissionShiftLag setFloatValue:[transmission shiftLag]];
  186.     shiftPoints = [transmission shiftPoints];
  187.     for ( i = 0 ; i < 4 ; i++ )
  188.         [transmissionShiftPoints setFloatValue:shiftPoints[i] at:i];
  189.     return self;
  190. }
  191.  
  192. - setEngineBox:anObject;
  193. {
  194.     engineBox = anObject;
  195.     boxList[4] = anObject;
  196.     return self;
  197. }
  198.  
  199. - OKEngineBox:sender
  200. {
  201. float coefficients[6];
  202. int i; 
  203. float redline;
  204.     
  205.     redline = [engineRedline floatValue];
  206.  
  207.     for ( i = 0 ; i < 6 ; i++ )
  208.         coefficients[i] = [engineCoefficients floatValueAt:i];
  209.     [engine setCoefficients:coefficients];
  210.     [engine setEfficiency:[engineEfficiency floatValue]];
  211.     [engine setMass:[engineMass floatValue]];
  212.     [engine setRedline:redline];
  213.     [engine setStallSpeed:[engineStallSpeed floatValue]];
  214.     [engine setStartLag:[engineStartLag floatValue]];
  215.     [engineGraph setPlotMode:CURVE_ONLY];
  216.     [engineGraph setCurveFromArray:coefficients count:6];
  217.     [engineGraph rescaleForCurveWithRange:0 :redline checkInterval:redline/100];
  218.     [inspectorPanel display];    
  219.     return self;
  220. }
  221.  
  222. - revertEngineBox:sender
  223. {
  224. float *coefficients;
  225. int i;
  226. float redline;
  227.  
  228.     redline = [engine redline];
  229.  
  230.     coefficients = [engine coefficients];
  231.     for ( i = 0 ; i < 6 ; i++ )
  232.         [engineCoefficients setFloatValue:coefficients[i] at:i];
  233.     [engineEfficiency setFloatValue:[engine efficiency]];
  234.     [engineMass setFloatValue:[engine mass]];
  235.     [engineRedline setFloatValue:redline];
  236.     [engineStallSpeed setFloatValue:[engine stallSpeed]];
  237.     [engineStartLag setFloatValue:[engine startLag]];
  238.     [engineGraph setPlotMode:CURVE_ONLY];
  239.     [engineGraph setCurveFromArray:coefficients count:6];
  240.     [engineGraph rescaleForCurveWithRange:0 :redline checkInterval:redline/100];
  241.     [inspectorPanel display];
  242.     return self;
  243. }
  244.  
  245. - setGasTankBox:anObject;
  246. {
  247.     gasTankBox = anObject;
  248.     boxList[5] = anObject;
  249.     return self;
  250. }
  251.  
  252. - OKGasTankBox:sender
  253. {
  254.     [gasTank setCurrent:[gasTankCurrent doubleValue]];
  255.     [gasTank setEnergyDensity:[gasTankEnergyDensity floatValue]];
  256.     [gasTank setFuelDensity:[gasTankFuelDensity floatValue]];
  257.     [gasTank setMass:[gasTankMass floatValue]];
  258.     [gasTank setMax:[gasTankMax floatValue]];    
  259.     return self;
  260. }
  261.  
  262. - revertGasTankBox:sender
  263. {
  264.     [gasTankCurrent setDoubleValue:[gasTank current]];
  265.     [gasTankEnergyDensity setFloatValue:[gasTank energyDensity]];
  266.     [gasTankFuelDensity setFloatValue:[gasTank fuelDensity]];
  267.     [gasTankMass setFloatValue:[gasTank mass]];
  268.     [gasTankMax setFloatValue:[gasTank max]];
  269.     return self;
  270. }
  271.  
  272. - setMotorBox:anObject;
  273. {
  274.     motorBox = anObject;
  275.     boxList[6] = anObject;
  276.     return self;
  277. }
  278.  
  279. - OKMotorBox:sender
  280. {
  281. float lowEndCoefficients[6];
  282. float highEndCoefficients[6];
  283. int i;
  284. float max;
  285.  
  286.     max = [motorMax floatValue];
  287.  
  288.     [motor setCrossover:[motorCrossover floatValue]];
  289.     [motor setEfficiency:[motorEfficiency floatValue]];
  290.     for ( i = 0 ; i < 6 ; i++ )
  291.         lowEndCoefficients[i] = [motorLowCoefficients floatValueAt:i];
  292.     [motor setLowCoefficients:lowEndCoefficients];
  293.     for ( i = 0 ; i < 6 ; i++ )
  294.         highEndCoefficients[i] = [motorHighCoefficients floatValueAt:i];
  295.     [motor setHighCoefficients:highEndCoefficients];
  296.     [motor setMass:[motorMass floatValue]];
  297.     [motor setMax:max];
  298.     [motor setRegenerationEfficiency:[motorRegenerationEfficiency floatValue]];
  299.  
  300.     [motorHighEndGraph setPlotMode:CURVE_ONLY];
  301.     [motorHighEndGraph setCurveFromArray:highEndCoefficients count:6];
  302.     [motorHighEndGraph rescaleForCurveWithRange:0 :max checkInterval:max/100];
  303.     
  304.     [motorLowEndGraph setPlotMode:CURVE_ONLY];
  305.     [motorLowEndGraph setCurveFromArray:lowEndCoefficients count:6];
  306.     [motorLowEndGraph rescaleForCurveWithRange:0 :max checkInterval:max/100];
  307.  
  308.     [inspectorPanel display];
  309.     return self;
  310. }
  311.  
  312. - revertMotorBox:sender
  313. {
  314. float *lowEndCoefficients;
  315. float *highEndCoefficients;
  316. int i;
  317. float max;
  318.  
  319.     max = [motor max];
  320.  
  321.     [motorCrossover setFloatValue:[motor crossover]];
  322.     [motorEfficiency setFloatValue:[motor efficiency]];
  323.     lowEndCoefficients = [motor lowCoefficients];
  324.     for ( i = 0 ; i < 6 ; i++ )
  325.         [motorLowCoefficients setFloatValue:lowEndCoefficients[i] at:i];
  326.     highEndCoefficients = [motor highCoefficients];
  327.     for ( i = 0 ; i < 6 ; i++ )
  328.         [motorHighCoefficients setFloatValue:highEndCoefficients[i] at:i];
  329.     [motorMass setFloatValue:[motor mass]];
  330.     [motorMax setFloatValue:max];
  331.     [motorRegenerationEfficiency setFloatValue:[motor regenerationEfficiency]];
  332.  
  333.     [motorHighEndGraph setPlotMode:CURVE_ONLY];
  334.     [motorHighEndGraph setCurveFromArray:highEndCoefficients count:6];
  335.     [motorHighEndGraph rescaleForCurveWithRange:0 :max checkInterval:max/100];
  336.     
  337.     [motorLowEndGraph setPlotMode:CURVE_ONLY];
  338.     [motorLowEndGraph setCurveFromArray:lowEndCoefficients count:6];
  339.     [motorLowEndGraph rescaleForCurveWithRange:0 :max checkInterval:max/100];
  340.  
  341.     [inspectorPanel display];
  342.     return self;
  343. }
  344.  
  345. - setBatteryBox:anObject;
  346. {
  347.     batteryBox = anObject;
  348.     boxList[7] = anObject;
  349.     return self;
  350. }
  351.  
  352. - OKBatteryBox:sender
  353. {
  354. float ampCoefficients[6];
  355. float voltCoefficients[6];
  356. int i;
  357.  
  358.     for ( i = 0 ; i < 6 ; i++ )
  359.         ampCoefficients[i] = [batteryAmpCoefficients floatValueAt:i];
  360.     [battery setAmpCoefficients:ampCoefficients];
  361.     [battery setEfficiency:[batteryEfficiency floatValue]];
  362.     [battery setMass:[batteryMass floatValue]];
  363.     [battery setMax:[batteryMax floatValue]];
  364.     [battery setPeakDraw:[batteryPeakDraw floatValue]];
  365.     [battery setPlotAmps:[batteryPlotAmps state]];
  366.     [battery setPlotCharge:[batteryPlotCharge state]];
  367.     [battery setPlotVolts:[batteryPlotVolts state]];
  368.     [battery setPresent:[batteryPresent doubleValue]];
  369.     for ( i = 0 ; i < 6 ; i++ )
  370.         voltCoefficients[i] = [batteryVoltCoefficients floatValueAt:i];
  371.     [battery setVoltCoefficients:voltCoefficients];
  372.  
  373.     [batteryVoltGraph setPlotMode:CURVE_ONLY];
  374.     [batteryVoltGraph setCurveFromArray:voltCoefficients count:6];
  375.     [batteryVoltGraph rescaleForCurveWithRange:0 :[batteryMax floatValue] checkInterval:[batteryMax floatValue]/100];
  376.  
  377.     [batteryAmpGraph setPlotMode:CURVE_ONLY];
  378.     [batteryAmpGraph setCurveFromArray:ampCoefficients count:6];
  379.     [batteryAmpGraph rescaleForCurveWithRange:0 :[batteryMax floatValue] checkInterval:[batteryMax floatValue]/100];
  380.  
  381.     [inspectorPanel display];
  382.   
  383.     return self;
  384. }
  385.  
  386. - revertBatteryBox:sender
  387. {
  388. float *ampCoefficients;
  389. float *voltCoefficients;
  390. int i;
  391.  
  392.     ampCoefficients = [battery ampCoefficients];
  393.     for ( i = 0 ; i < 6 ; i++ )
  394.         [batteryAmpCoefficients setFloatValue:ampCoefficients[i] at:i];
  395.     [batteryEfficiency setFloatValue:[battery efficiency]];
  396.     [batteryMass setFloatValue:[battery mass]];
  397.     [batteryMax setFloatValue:[battery max]];
  398.     [batteryPeakDraw setFloatValue:[battery peakDraw]];
  399.     [batteryPlotAmps setState:[battery plotAmps]];
  400.     [batteryPlotCharge setState:[battery plotCharge]];
  401.     [batteryPlotVolts setState:[battery plotVolts]];
  402.     [batteryPresent setDoubleValue:[battery present]];
  403.     voltCoefficients = [battery voltCoefficients];
  404.     for ( i = 0 ; i < 6 ; i++ )
  405.         [batteryVoltCoefficients setFloatValue:voltCoefficients[i] at:i];
  406.  
  407.     [batteryVoltGraph setPlotMode:CURVE_ONLY];
  408.     [batteryVoltGraph setCurveFromArray:voltCoefficients count:6];
  409.     [batteryVoltGraph rescaleForCurveWithRange:0 :[batteryMax floatValue] checkInterval:[batteryMax floatValue]/100];
  410.  
  411.     [batteryAmpGraph setPlotMode:CURVE_ONLY];
  412.     [batteryAmpGraph setCurveFromArray:ampCoefficients count:6];
  413.     [batteryAmpGraph rescaleForCurveWithRange:0 :[batteryMax floatValue] checkInterval:[batteryMax floatValue]/100];
  414.  
  415.     [inspectorPanel display];
  416.  
  417.     return self;
  418. }
  419.  
  420. - setWheelBox:anObject;
  421. {
  422.     wheelBox = anObject;
  423.     boxList[8] = anObject;
  424.     return self;
  425. }
  426.  
  427. - OKWheelBox:sender
  428. {
  429.     [wheel setDiameter:[wheelDiameter floatValue]];
  430.     [wheel setMass:[wheelMass floatValue]];
  431.     [wheel setRollingResistance:[wheelRollingResistance floatValue]];
  432.     return self;
  433. }
  434.  
  435. - revertWheelBox:sender
  436. {
  437.     [wheelDiameter setFloatValue:[wheel diameter]];
  438.     [wheelMass setFloatValue:[wheel mass]];
  439.     [wheelRollingResistance setFloatValue:[wheel rollingResistance]];
  440.     return self;
  441. }
  442.  
  443. - setCycleBox:anObject;
  444. {
  445.     cycleBox = anObject;
  446.     boxList[9] = cycleBox;
  447.     return self;
  448. }
  449.  
  450. - OKCycleBox:sender
  451. {
  452.     [cycle setEnd:[cycleEnd floatValue]];
  453.     [cycle setStart:[cycleStart floatValue]];
  454.     return self;
  455. }
  456.  
  457.  
  458. - revertCycleBox:sender
  459. {
  460.     [cycleEnd setFloatValue:[cycle end]];
  461.     [cycleStart setFloatValue:[cycle start]];
  462.     return self;
  463. }
  464.  
  465. - loadCycle:sender;
  466. {
  467. char *filename;
  468.  
  469.     filename = [appDelegate openFileType:"cycle"];
  470.     [self updateCycleGraph:filename];
  471.     return self;
  472. }
  473.  
  474. - updateCycleGraph:(const char *)filename
  475. {
  476.     strcpy(windowTitles[9],filename);
  477.     [cycleGraph setData:[cycle data]];
  478.     [cycleGraph setZeroLines:NO];
  479.     [inspectorPanel setTitleAsFilename:windowTitles[9]];
  480.     [cycleStart setFloatValue:[cycleGraph xmin]];
  481.     [cycleEnd setFloatValue:[cycleGraph xmax]];
  482.     [cycle setLength:[cycleGraph xmax]];
  483.     [cycleLength setFloatValue:[cycle length]];
  484.     [self OKCycleBox:self];
  485.     [inspectorPanel display];
  486.     return self;    
  487. }
  488.  
  489. - flipInspector:sender
  490. {
  491. int i;
  492. id view;
  493.  
  494.     [self updateBoxes];
  495.     i = [sender tag];
  496.     view = [boxList[i] contentView];
  497.     [inspectorPanel setTitleAsFilename:windowTitles[i]];
  498.     [inspectorBox setContentView:view];
  499.     [inspectorBox display];
  500.     return self;
  501. }
  502.  
  503. - updateBoxes
  504. {
  505.     [self revertRoadBox:self];
  506.     [self revertCarBox:self];
  507.     [self revertControllerBox:self];
  508.     [self revertTransmissionBox:self];
  509.     [self revertEngineBox:self];
  510.     [self revertGasTankBox:self];
  511.     [self revertMotorBox:self];
  512.     [self revertBatteryBox:self];
  513.     [self revertWheelBox:self];
  514.     [self revertCycleBox:self];
  515.     return self;
  516. }
  517.  
  518. @end
  519.